package org.example.ttl;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class TopicsProducer {


    /**
     * 正常的交换机名称
     */
    public static final String QUEUE_NAME = "normal_exchange4";


    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            //声明广播类型的交换机
            channel.exchangeDeclare(QUEUE_NAME, BuiltinExchangeType.TOPIC);
            //声明一个交换机
            //设置队列的ttl
            for (int i = 0; i < 10; i++) {
                //设置消息的ttl
                String randomMessage = "消息" + i;
                channel.basicPublish(QUEUE_NAME, "orange", null, randomMessage.getBytes());
            }
            // In the Java client, when we supply no parameters to queueDeclare() we
            // create a non-durable, exclusive, autodelete queue with a generated name:
            // AMQP.Queue.DeclareOk declareOk = channel.queueDeclare();
            // 获取一个非持久化，排他，自动删除的队列
            // String queueName = declareOk.getQueue();
            // channel.queueBind(queueName,PUB_EXCHANGE,"");
        }
    }


}
